<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class CompanyAssetUtilization extends Page
{
       public $Image3 = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $edHoursSun = null;
       public $edHoursSat = null;
       public $edHoursFri = null;
       public $edHoursThu = null;
       public $edHoursWed = null;
       public $edHoursTue = null;
       public $edHoursMon = null;
       public $edMilesSun = null;
       public $edMilesSat = null;
       public $edMilesFri = null;
       public $edMilesThu = null;
       public $edMilesWed = null;
       public $edMilesTue = null;
       public $lblHours = null;
       public $edMilesMon = null;
       public $lblMiles = null;
       public $lblSun = null;
       public $lblSat = null;
       public $lbFri = null;
       public $lblThu = null;
       public $lblWed = null;
       public $lblTue = null;
       public $lblMon = null;
       public $JTGroupDailyUtilization = null;
       public $JTSiteTheme1 = null;

       function btnSubmitClick($sender, $params)
       {

       $result=mysql_query("select * from company_asset_tbl where company_id='".$_SESSION['company_id']."'");
       $count=mysql_num_rows($result);
       if($count==0)
       {
       mysql_query("insert into company_asset_tbl (company_id,
       miles_mon,
       miles_tue,
       miles_wed,
       miles_thu,
       miles_fri,
       miles_sat,
       miles_sun,
       hours_mon,
       hours_tue,
       hours_wed,
       hours_thu,
       hours_fri,
       hours_sat,
       hours_sun)

       Values('".$_SESSION['company_id']."',
       '".$this->edMilesMon->Text."',
       '".$this->edMilesTue->Text."',
       '".$this->edMilesWed->Text."',
       '".$this->edMilesThu->Text."',
       '".$this->edMilesFri->Text."',
       '".$this->edMilesSat->Text."',
       '".$this->edHoursMon->Text."',
       '".$this->edHoursTue->Text."',
       '".$this->edHoursWed->Text."',
       '".$this->edHoursTue->Text."',
       '".$this->edHoursThu->Text."',
       '".$this->edHoursFri->Text."',
       '".$this->edHoursSat->Text."',
       '".$this->edHoursSun->Text."')") or die ("insert asset - " . mysql_error());
       }
       else
       {
       mysql_query("update company_asset_tbl set
       miles_mon='".$this->edMilesMon->Text."',
       miles_tue='".$this->edMilesTue->Text."',
       miles_wed='".$this->edMilesWed->Text."',
       miles_thu='".$this->edMilesThu->Text."',
       miles_fri='".$this->edMilesFri->Text."',
       miles_sat='".$this->edMilesSat->Text."',
       hours_mon='".$this->edHoursMon->Text."',
       hours_tue='".$this->edHoursTue->Text."',
       hours_wed='".$this->edHoursWed->Text."',
       hours_thu='".$this->edHoursThu->Text."',
       hours_fri='".$this->edHoursFri->Text."',
       hours_sat='".$this->edHoursSat->Text."',
       hours_sun='".$this->edHoursSun->Text."'
       where company_id='".$_SESSION['company_id']."'") or die ("update asset - " . mysql_error());
       }
       redirect('vehicle_list.php?company_id='.$_SESSION['company_id']);


       }

       function btnCancelClick($sender, $params)
       {
       redirect('vehicle_list.php?company_id='.$_SESSION['company_id']);
       }

       function CompanyAssetUtilizationCreate($sender, $params)
       {

       $query = "select * from company_asset_tbl where company_id='".$_SESSION['company_id']."'";
       $result_show = mysql_query($query)or die("SELECT ASSET - " . mysql_error());
       $row= mysql_fetch_array($result_show);

       $this->edMilesMon->Text = $row['miles_mon'];
       $this->edMilesTue->Text = $row['miles_tue'];
       $this->edMilesWed->Text = $row['miles_wed'];
       $this->edMilesThu->Text = $row['miles_thu'];
       $this->edMilesFri->Text = $row['miles_fri'];
       $this->edMilesSat->Text = $row['miles_sat'];
       $this->edMilesSun->Text = $row['miles_sun'];
       $this->edHoursMon->Text = $row['hours_mon'];
       $this->edHoursTue->Text = $row['hours_tue'];
       $this->edHoursWed->Text = $row['hours_wed'];
       $this->edHoursThu->Text = $row['hours_thu'];
       $this->edHoursFri->Text = $row['hours_fri'];
       $this->edHoursSat->Text = $row['hours_sat'];
       $this->edHoursSun->Text = $row['hours_sun'];

       }

}

global $application;

global $CompanyAssetUtilization;

//Creates the form
$CompanyAssetUtilization=new CompanyAssetUtilization($application);

//Read from resource file
$CompanyAssetUtilization->loadResource(__FILE__);

//Shows the form
$CompanyAssetUtilization->show();

?>